﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommHelper;

namespace SocketSample
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            bool ret;
            System.Threading.Mutex mutex = new System.Threading.Mutex(true, "SokectSample", out ret);
            if (ret)
            {
                RegisterUnHandledException();
                SHDServer.SocketServer socketServer = new SHDServer.SocketServer();
                socketServer.Start();
                ReadKey();
            }
        }

        private static void ReadKey()
        {
            if (Console.ReadKey().Key == ConsoleKey.Escape)
            {
                Environment.Exit(Environment.ExitCode);
            }
            else
            {
                ReadKey();
            }
        }

        private static void RegisterUnHandledException()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            LogHelper.WriteErrorLog((e.ExceptionObject as Exception).Message);
        }
    }
}